<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/12/6
 * Time: 11:23
 */

namespace app\enterprise\service;


class My
{
    public $url = '';
    function __construct()
    {
        $this->url = config('setting.base_url');
    }
    /**
     * 获取用户信息
     * @param $token
     * @return null
     */
    public function getUserInfo($token){
        $url = $this->url."/enterprise/user";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->error_code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取小程序二维码
     * @param $token
     * @return null
     */
    public function getQrCode($token){
        $url = $this->url."/enterprise/qrcode";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 更新头部信息
     * @param $token
     * @param $img
     * @return null
     */
    public function updateImg($token,$img){
        $url = $this->url."/enterprise/user/head";
        $params = ['head_img'=>$img['head_img'],'style'=>$img['style']];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 获取用户基本信息
     * @param $token
     * @return null
     */
    public function getBaseInfo($token){
        $url = $this->url."/enterprise/base_info";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 用户基本信息
     * @param $token
     * @return null
     */
    public function getMessageInfo($token){
        $url = $this->url."/enterprise/card_base_info";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 更新与用户基本信息
     * @param $token
     * @return null
     */
    public function updateMessageInfo($token,$data){
        $url = $this->url."/enterprise/update_card";
        unset($data['token']);
        $pagrams = $data;
        $result = curl_post($url,$token,$pagrams);
        $info = json_decode($result);
        if ($info->code == 200){
            return $info->content;
        }else{
            return null;
        }
    }

    /**
     * 请求推荐商品
     * @param $token
     * @return null
     */
    public function getUserGoods($token){
        $url = $this->url."/enterprise/goods";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 添加推荐商品
     * @param $token
     * @param $goods
     * @return null
     */
    public function addUserGoods($token,$goods){
        $url = $this->url."/enterprise/goods_add";
        $params = ['goods'=>$goods];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 获取分类
     * @param $token
     * @return null
     */
    public function getCategoryByUser($token){
        $url = $this->url."/enterprise/goods/category";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 获取商品
     * @param $token
     * @param $category
     * @return null
     */
    public function getGoodsByUser($token,$category,$page){
        $url = $this->url."/enterprise/goods/list/".$category.'/'.$page;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取名片拓展信息
     * @param $token
     * @return null
     */
    public function getExtendInfo($token){
        $url = $this->url."/enterprise/extend";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取微信素材
     * @param $token
     * @param $corpid
     * @param $media_id
     * @return |null
     */
    public function addAudio($token,$corpid,$media_id){
        $url = $this->url."/enterprise/material/audio";
        $params = ['corpid'=>$corpid,'media_id'=>$media_id];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 添加拓展信息
     * @param $token
     * @param $synopsisArr
     * @param $audioArr
     * @param $labelArr
     * @param $imgArr
     * @return null
     */
    public function addExtendInfo($token,$synopsisArr,$audioArr,$labelArr,$imgArr){
        $url = $this->url."/enterprise/extend/add";
        $params = ['synopsis'=>$synopsisArr,'audio'=>$audioArr,'label'=>$labelArr,'img'=>$imgArr];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }


    /**
     * 获取视频信息
     * @param $token
     * @return null
     */
    public function getVideoInfo($token){
        $url = $this->url."/enterprise/video";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取视频信息
     * @param $token
     * @return null
     */
    public function getShareWord($token){
        $url = $this->url."/enterprise/share";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 更新欢迎语
     * @param $info
     * @param $token
     * @return null
     */
    public function updateShareWord($info,$token){
        $url = $this->url."/enterprise/share/add";
        $params = ['share_word'=>$info['share_word'],'id'=>$info['id']];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 获取视频信息
     * @param $token
     * @return null
     */
    public function getWelcomeWord($token){
        $url = $this->url."/enterprise/welcome";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 更新欢迎语
     * @param $info
     * @param $token
     * @return null
     */
    public function updateWelcomeWord($info,$token){
        $url = $this->url."/enterprise/welcome/add";
        $params = ['welcome_word'=>$info['welcome_word'],'id'=>$info['id']];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
 * h获取话术分类
 * @param $token
 * @return null
 */
    public function getWordCategory($token){
        $url = $this->url."/workword/user/category";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * h获取话术分类l列表
     * @param $token
     * @return null
     */
    public function getWordListByCategory($token,$categoryId){
        $url = $this->url."/workword/user/category/".$categoryId;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 自定义话术添加
     * @param $info
     * @param $token
     * @return null
     */
    public function addTalk($info,$token){
        $url = $this->url."/workword/user/add";
        $params = ['keyword'=>$info['keyword'],'content'=>$info['content']];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 自定义话术添加
     * @param $info
     * @param $token
     * @return null
     */
    public function updateTalk($info,$token){
        $url = $this->url."/workword/user/update";
        $params = ['keyword'=>$info['keyword'],'content'=>$info['content'],'id'=>$info['id']];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 自定义话术列表
     * @param $info
     * @param $token
     * @return null
     */
    public function talkList($token){
        $url = $this->url."/workword/user/list";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取自定义话术
     * @param $info
     * @param $token
     * @return null
     */
    public function getTalk($token,$id){
        $url = $this->url."/workword/user/word/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data;
        }else{
            return null;
        }
    }

    /**
     * 删除自定义话术
     * @param $info
     * @param $token
     * @return null
     */
    public function deleteTalk($token,$id){
        $url = $this->url."/workword/user/delete/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }





}